feat(pgsql-test): add getErrorCode helper and fix pgpm_migrate exception context #548
+61
−77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(pgsql-test): add getErrorCode helper and fix pgpm_migrate exception context
Summary
This PR makes two related changes:
1. Add
getErrorCode()helper to pgsql-testSince pgsql-test 2.21.0,
PgTestClientappends additional debug context (Where, Query, Values) to error messages by default. This breaks tests that use exact string matching likeexpect(err.message).toEqual('NONEXISTENT_TYPE').The new helper extracts just the first line (the actual error code):
2. Fix pgpm_migrate exception handling to preserve SQL context
The
pgpm_migrate.deployandpgpm_migrate.revertprocedures were usingRAISE EXCEPTION USINGto re-raise errors, which loses thePG_EXCEPTION_CONTEXT(including the actual SQL statement that failed).Changed to use simple
RAISE;which preserves the full original exception context, keeping valuable debugging info like:Updates since last revision
RAISE EXCEPTION USINGtoRAISE;in bothdeployandrevertprocedures to preserve original exception contexterr.message. This is correct behavior - these tests verify enhanced error messages work in the migration flow.Review & Testing Checklist for Human
pnpm testinpostgres/pgsql-test/) and verify all pgpm-migration-errors snapshots pass - the snapshots were updated based on CI output, not local testingwherefield (should show "line 46 at EXECUTE", not "line 73 at RAISE")RAISE;changeRecommended test plan:
pnpm testinpostgres/pgsql-test/wherefieldNotes
This is part of fixing the test failures in constructive-db PR #190, where the pgsql-test upgrade caused tests to fail due to enhanced error message formatting.
Link to Devin run: https://app.devin.ai/sessions/6b89db7666a04391bbc93c493698f0df
Requested by: Dan Lynch (@pyramation)